<script>
	const db = uniCloud.database();
	import store from '@/store/index.js';
	export default {
		onLaunch: function() {
			this.update()
			this.getCookie()
			if (uni.getStorageSync('uni_id_token') && this.client != 'web') {
				this.getUserInfo()
			}
		},
		onShow: function() {
			if (this.client == "web") {
				var index = window.location.pathname.replace("/", "")
				if (index.indexOf('/') > 0 || index == "") {
					return
				}
				db.collection("link").where({
					index: index
				}).get({
					getOne: true
				}).then(res => {
					uni.redirectTo({
						url: './pages/share/share?id=' + res.result.data.item_id
					});
				});
			}
		},
		methods: {
			getCookie() {
				db.collection('options').where({
					name: "cookie"
				}).get({
					getOne: true
				}).then(res => {
					store.commit('setCookie', res.result.data.value)
				})
			},
			update() {
				db.collection('options').where({
					name: "版本"
				}).get({
					getOne: true
				}).then(res => {
					let value = res.result.data.value
					if (value.versionnumber > Number(uni.getSystemInfoSync().appVersionCode)) {
						uni.showModal({
							title: `${value.version}版本更新提示`,
							content: value.content,
							success: function(re1) {
								if (re1.confirm) {
									plus.runtime.openURL("http://x2.ink/app")
									plus.runtime.quit();
								} else if (re1.cancel) {
									if (value.force) {
										plus.runtime.openURL("http://x2.ink/app")
										plus.runtime.quit();
									}
								}
							}
						});
					}
				})
			}
		},
		globalData: {
			getLanZouInfo: "http://f.x2.ink:8000/getLanZouInfo"
		}
	}
</script>

<style lang="scss">
	@import "@/uni_modules/uview-ui/index.scss";
	@import url("./static/font/iconfont.css");


	.iconfont {
		font-family: "iconfont" !important;
		font-size: 16px;
		font-style: normal;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
	}

	page {
		background-color: #f5f5f5;
	}
</style>